﻿using Commands;
using Commands.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SecurityPlugin
{
    public class CommandsList : CommandListBase
    {
        /// <summary>
        /// Get current computer IP in internet."
        /// </summary>
        [RemoteCommand("Get current computer IP in internet.", "ip")]
        public bool GetComputerAddress([MailAddressParameter()] string mail)
        {
            Mailer.SendMail(mail, "IP", _GetExternalIP());

            return true;
        }

        private string _GetExternalIP()
        {
            string externalIP;
            externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
            externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
                         .Matches(externalIP)[0].ToString();

            return externalIP;
        }

    }
}
